<!--包含头部文件-->
{include file="public/header" /}
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 商品管理 <span class="c-gray en">&gt;</span> 商品列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="text-c">
		<form class="Huiform" method="post" action="{:url('goods/add')}" target="_self" enctype="multipart/form-data">
			<input type="text" placeholder="商品品牌" value="" class="input-text" name="brand" style="width:120px">
			<span class="btn-upload form-group">
			<input class="input-text upload-url" type="text" name="image" id="uploadfile-2" readonly style="width:200px">
			<a href="javascript:void();" class="btn btn-primary upload-btn"><i class="Hui-iconfont">&#xe642;</i> 上传logo</a>
			<input type="file" name="image" class="input-file">
			</span> <span class="select-box" style="width:150px">
			<select class="select firstId" name="category1_id" size="1">
				<option value="0" selected>一级分类</option>
				{volist name="types" id="vo"}
					<option value="{$vo.id}">|---{$vo.name}</option>
				{/volist}
			</select>
			</span>
			<span class="select-box" style="width:150px">
				<select class="select secType" name="category2_id" size="1">
					<option value="0" selected>二级分类</option>
				</select>
			</span>
			<button type="submit" class="btn btn-success" id="" name="" ><i class="Hui-iconfont">&#xe600;</i> 添加</button>
		</form>
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a></span> <span class="r">共有数据：<strong>{$count}</strong> 条</span> </div>
	<div class="mt-20">
		<table class="table table-border table-bordered table-bg table-sort">
			<thead>
				<tr class="text-c">
					<th width="25"><input type="checkbox" name="" value=""></th>
					<th width="50">ID</th>
					<th width="50">商品品牌</th>
					<th width="200">LOGO</th>
					<th width="120">商品名</th>
					<th width="40">价格</th>
					<th width="40">库存</th>
					<th width="60">发布状态</th>
					<th width="100">操作</th>
				</tr>
			</thead>
			<tbody>
				{volist name="goods" id="vo"}
				<tr class="text-c">
					<td><input name="" type="checkbox" value=""></td>
					<td>{$vo.id}</td>
					<td>{$vo.brand}</td>
					<td><img src="{$vo.picture}" height="60"></td>
					<td class="text-l">{$vo.gname}</td>
					<td class="price"><input type="text" attr-id="{$vo.id}" class="input-text text-c" value="{$vo.price}" name=""></td>
					<td class="stock"><input type="text" attr-id="{$vo.id}" class="input-text text-c" value="{$vo.stock}" name=""></td>
					<td class="td-status">{$vo.status}</td>
					<td class="f-14 product-brand-manage"><a style="text-decoration:none" href="{:url('goods/details',['id'=>$vo.id])}" title="详情"><i class="Hui-iconfont">&#xe6df;</i></a> <a style="text-decoration:none" class="ml-5" onClick="o2o_del('{:url('goods/delete',['id'=>$vo.id,'dels'=>0])}')" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
				</tr>
				{/volist}
			</tbody>
		</table>
	</div>
</div>
<div class="cl pd-5 bg-1 bk-gray mt-20 tp5-o2o">{$goods->render()}</div>
<!--包含头部文件-->
{include file="public/footer" /}
<script>
var SCOPE = {
	'secondType_url': "{:url('type/getSecondType')}",
	'price_url' : "{:url('goods/changeprice')}",
	'stock_url' : "{:url('goods/changestock')}",
  };
$('.firstId').change(function(){
	firstId = $(this).val();
	data = {'id':firstId};
	url = SCOPE.secondType_url;
	$.post(url,data,function(result){
		if (result.status == 1) {
			data = result.data['data'];
			sec_html = '';
			  $(data).each(function(i){
	                sec_html += "<option value='"+this.id+"'>"+this.name+"</option>";

	           });
			$('.secType').html(sec_html);
		}else if(result.status == 0){
			$('.secType').html('');
			return;
		}
	},'json');
});

// 修改价格
$('.price input').blur(function(){
	// 获取主键ID
	id = $(this).attr('attr-id');
	// 获取更改的价格
	price = $(this).val();
	var data = {
		'id' : id,
		'price' : price
	};
	url = SCOPE.price_url;
	$.post(url,data,function(result){
		if(result.code == 1) {
            location.href=result.data;
        }else {
            alert(result.msg);
        }
	},'json');
});

// 修改库存
$('.stock input').blur(function(){
	// 获取主键ID
	id = $(this).attr('attr-id');
	// 获取更改的价格
	stock = $(this).val();
	var data = {
		'id' : id,
		'stock' : stock
	};
	url = SCOPE.stock_url;
	$.post(url,data,function(result){
		if(result.code == 1) {
            location.href=result.data;
        }else {
            alert(result.msg);
        }
	},'json');
});
</script>
</body>
</html>